package com.huaboot.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huaboot.commont.page.PageResult;
import com.huaboot.system.convert.GenTestStudentConvert;
import com.huaboot.system.entity.GenTestStudentEntity;
import com.huaboot.system.query.GenTestStudentQuery;
import com.huaboot.system.vo.GenTestStudentVO;
import com.huaboot.system.mapper.GenTestStudentMapper;
import com.huaboot.system.service.GenTestStudentService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;



/**
 * 测试2
 *
 * @author ff 1
 * @since 1.0.0 2023-08-22
 */
@Service
@AllArgsConstructor
public class GenTestStudentServiceImpl extends ServiceImpl<GenTestStudentMapper, GenTestStudentEntity> implements GenTestStudentService {

    @Override
    public PageResult<GenTestStudentVO> page(GenTestStudentQuery query) {
        PageHelper.startPage(query.currentPage, query.size);

        List<GenTestStudentEntity> GenTestStudentEntityList = list(getWrapper(query));
        PageInfo<GenTestStudentEntity> page = new PageInfo<>(GenTestStudentEntityList);
        return new PageResult<>(GenTestStudentConvert.INSTANCE.convertList(page.getList()), page.getTotal());
    }

    private LambdaQueryWrapper<GenTestStudentEntity> getWrapper(GenTestStudentQuery query){
        LambdaQueryWrapper<GenTestStudentEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(GenTestStudentVO vo) {
        GenTestStudentEntity entity = GenTestStudentConvert.INSTANCE.convert(vo);
         save(entity);
    }

    @Override
    public void update(GenTestStudentVO vo) {
        GenTestStudentEntity entity = GenTestStudentConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}
